#!/bin/sh
# e2fsprogs_static
# Builds from https://github.com/puppylinux-woof-CE/petbuilds

. ../../func

# GOES TO INITRD

VER=1.43.9
#URL=https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v${VER}
URL=https://sourceforge.net/projects/e2fsprogs/files/e2fsprogs/v${VER}
SRC=e2fsprogs
PKG=e2fsprogs_static
COMP=tar.gz
DESC=""
DEPS=
CAT=BuildingBlock
CWD=`pwd`

build() {
	cd ${SRC}-${VER}
	opts='--prefix=/usr
--disable-nls
--disable-elf-shlibs
--disable-bsd-shlibs
--disable-rpath
--disable-debugfs       disable support of debugfs program
--disable-imager        disable support of e2image program
--disable-defrag        disable support of e4defrag program
--disable-tls           disable use of thread local support
--disable-uuidd         disable building the uuid daemon
--disable-nls
--disable-fuse2fs
--disable-testio-debug
--disable-bmap-stats
--disable-mmp
--disable-tdb
--enable-libblkid
--enable-libuuid
'
	opts=$(echo "$opts" | sed 's| .*||')
	export CFLAGS=$(_cflags)
	_configure
	sed -i -e 's|.so$|.a|' -e 's|.so |.a |' $(find . -type f -name Makefile)
	_make ${MKFLG} LDFLAGS=-static
	EXEC_E2=`find . -type f -name 'e2fsck'`
	EXEC_RS=`find . -type f -name 'resize2fs'`
	abort_if_file_not_found $EXEC_E2 $EXEC_RS
	install -d -m 0755 $CWD/${PKG}-${VER}-${ARCH}/bin
	_install $EXEC_E2 $CWD/${PKG}-${VER}-${ARCH}/bin
	_install $EXEC_RS $CWD/${PKG}-${VER}-${ARCH}/bin
	cd -
}

package() {
	# add this recipe
	install -d -m 0755 ./${PKG}-${VER}-${ARCH}/build
	cat ${PKG}.petbuild > ./${PKG}-${VER}-${ARCH}/build/$PKG-build-recipe
	# move, don't package
	cp -a --remove-destination ./${PKG}-${VER}-${ARCH}/* ../../00_${ARCH}
	rm -r ${SRC}-${VER}
	rm -r ${PKG}-${VER}-${ARCH}
	echo "moved to initrd"
	echo "done!"
}

# main
retrieve ${SRC}-${VER}.${COMP}
[ "$DLD_ONLY" = "yes" ] && exit
extract ${SRC}-${VER}.${COMP}
build
package
